﻿

$(function () {


    $.ajax({
        url: '/APP/Home/GetCommodityInfoList',
        type: "get",
        data: {
            page: 1,
            limit: 12
        },
        success: function (res) {

            console.log("111", res);
            for (var i = 0; i < res.data.length; i++) {
                console.log("111", res.data);
                var item = res.data[i];//获取一个商品
                var a = 1;
                var temp = `

                    <div class="col-xs-12 col-md-3">
                            <div class="thumbnail">

                                <img class="imgId product-img" src="/API/File/Download/${item.imgUrl}" id="${item.id}" />

                            </div>
                             <div class="clearfix absolute name-product-no-ranking">
                                            <p class="title-product clearfix full-width title-hover-black"><a href="#">${item.commodityName}</a></p>
                                            <p class="clearfix price-product">￥${item.money}</p>
                             </div>

                             <button class="btn btn-primary backk">购买</button>
                        </div>



                `;
                $(".product-son").append(temp);



            }
            $(".backk").click(function () {
                var imgId = $(this).siblings().find("img").attr("id");
                console.log(imgId);
                $.ajax({
                    url: "/admin/CommodityInfo/Purchase",
                    type: "post",
                    data: {
                        productId: imgId,
                    },
                    success: function (res) {
                        layer.msg(res.msg)
                    }
                })
            })
        }
    });

})



















